﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>弹出选择面板 - 选择负责人</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="../demo.css" rel="stylesheet" type="text/css" />

    
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    
    <style type="text/css">
        .New_Button, .Edit_Button, .Delete_Button, .Update_Button, .Cancel_Button
        {
            font-size:11px;color:#1B3F91;font-family:Verdana;  
            margin-right:5px;
        }
       
                
    </style>        

    <script src="../CommonLibs/UserSelectWindow.js" type="text/javascript"></script>    

</head>
<body>
    <h1>弹出选择面板 - 选择负责人</h1>      

    <input type="button" value="保存" onclick="saveData()" />

    <div id="datagrid1" class="mini-datagrid" style="width:600px;height:280px;" allowResize="true"
        url="../data/AjaxService.jsp?method=GetDepartments"  idField="id"
        allowCellEdit="true" allowCellSelect="true"
    >
        <div property="columns">                 
            <div field="id" width="60" headerAlign="center" align="center">ID</div>                                        
            <div field="name" width="120" headerAlign="left" >部门名称</div>          
            <div field="manager" displayField="manager_name" name="manager" width="120" headerAlign="left" >负责人
                <input property="editor" class="mini-buttonedit" onbuttonclick="onButtonEdit" style="width:100%;"/>
            </div>
        </div>
    </div>     
    
    
    <script type="text/javascript">
        mini.parse();

        var grid = mini.get("datagrid1");
        grid.load();

        //-----------------------------------------

        function saveData(row_uid) {

            var rowsData = grid.getChanges();

            grid.loading("保存中，请稍后......");
            var json = mini.encode(rowsData);
            $.ajax({
                url: "../data/AjaxService.jsp?method=SaveDepartment",
                data: { departments: json },
                success: function (text) {
                    grid.reload();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });

        }
        /////////////////////////////////////////////

        var win = null;
        function onButtonEdit(e) {

            var buttonEdit = e.sender;

            if (!win) {
                win = new UserSelectWindow();
                win.set({
                    url: bootPATH + "../demo/data/AjaxService.jsp?method=SearchEmployees",
                    title: "用户选择",
                    width: 600,
                    height: 350
                });
            }

            win.show();
            win.search();

            //初始化数据
            win.setData(null, function (action) {
                if (action == "ok") {
                    //获取数据
                    var data = win.getData();
                    if (data) {
                        var row = grid.getSelected();
                        grid.updateRow(row, {
                            manager: data.id,
                            manager_name: data.name
                        });
                    }
                }
            });
        }

    </script>

</body>
</html>